package sicnu.cs.aps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import sicnu.cs.aps.common.enums.ActivityAuditEnum;
import sicnu.cs.aps.common.enums.ActivitySignEnum;
import sicnu.cs.aps.domain.entity.ActivityAudit;
import sicnu.cs.aps.domain.vo.TimeEventVo;
import sicnu.cs.aps.mapper.ActivityAuditMapper;
import sicnu.cs.aps.service.IActivityAuditService;

import java.util.ArrayList;
import java.util.List;

/**
 * description 审核记录表service实现
 *
 * @author chenhetao
 * @version 1.0
 * @className ActivityAuditServiceImpl
 * @packageName sicnu.cs.aps.service.impl
 * @date 2022/6/1 15:13
 */
@Service
@AllArgsConstructor
public class ActivityAuditServiceImpl extends ServiceImpl<ActivityAuditMapper, ActivityAudit> implements IActivityAuditService {
    private final ActivityAuditMapper auditMapper;

    @Override
    public List<TimeEventVo> listTeamAuditTimeLine(Long teamId) {
        List<TimeEventVo> timeEventVos = new ArrayList<>();
        List<ActivityAudit> activityAudits = auditMapper.listByTeamId(teamId);
        if (activityAudits.isEmpty()) {
            return null;
        }
        activityAudits.forEach(activityAudit -> {
                    try {
                        timeEventVos.add(
                                TimeEventVo.builder()
                                        .opTime(activityAudit.getOpinionTime())
                                        .opEventDesc(activityAudit.getOpinion())
                                        .opDesc(ActivitySignEnum.getEnum(activityAudit.getType()).getDesc())
                                        .operatorId(activityAudit.getOptionUserId())
                                        .operatorName(activityAudit.getOptionUserName())
                                        .opEvent(ActivitySignEnum.getEnum(activityAudit.getType()))
                                        .build());
                    } catch (Exception e) {
                        log.error("组装失败==>" + activityAudit);
                    }

                }
        );
        return timeEventVos;
    }
}
